package com.xmtlxx.web.controller.center;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.xmtlxx.web.controller.center.service.ICenterService;
import com.xmtlxx.web.controller.center.vo.SendTaskVo;
import com.xmtlxx.web.controller.oms.service.IPropertyService;
import com.xmtlxx.web.controller.oms.service.ITaskService;
import com.xmtlxx.web.controller.tms.service.IOrderLogService;
import com.xmtlxx.web.controller.tms.service.IOrderService;
import com.xmtlxx.web.controller.tms.service.IWaybillService;
import com.xmtlxx.web.controller.wms.service.IDealService;
import com.xmtlxx.web.controller.wms.service.IExWarehouseService;
import com.xmtlxx.web.controller.wms.service.IWarehouseService;
import com.xmtlxx.web.controller.utils.OrderUtils;
import com.xmtlxx.tms.domain.bo.ClientBo;
import com.xmtlxx.tms.domain.bo.OrderBo;
import com.xmtlxx.tms.domain.bo.OrderLogBo;
import com.xmtlxx.tms.domain.vo.ClientVo;
import com.xmtlxx.tms.domain.vo.OrderDtlVo;
import com.xmtlxx.tms.domain.vo.OrderVo;
import com.xmtlxx.tms.service.ICarService;
import com.xmtlxx.tms.service.ICarrierService;
import com.xmtlxx.tms.service.IClientService;
import com.xmtlxx.wms.domain.bo.*;
import com.xmtlxx.wms.domain.vo.*;
import com.xmtlxx.wms.service.IInventoryService;
import com.xmtlxx.wms.service.IStoreLogService;
import com.xmtlxx.wms.service.IStoreService;
import com.xmtlxx.common.annotation.Log;
import com.xmtlxx.common.core.controller.BaseController;
import com.xmtlxx.common.core.domain.PageQuery;
import com.xmtlxx.common.core.domain.R;
import com.xmtlxx.common.core.domain.entity.SysUser;
import com.xmtlxx.common.core.page.TableDataInfo;
import com.xmtlxx.common.core.validate.AddGroup;
import com.xmtlxx.common.core.validate.QueryGroup;
import com.xmtlxx.common.enums.BusinessType;
import com.xmtlxx.common.helper.LoginHelper;
import com.xmtlxx.common.utils.DateUtils;
import com.xmtlxx.common.utils.JsonUtils;
import com.xmtlxx.common.utils.file.BASE64DecodedMultipartFile;
import com.xmtlxx.oms.domain.bo.OperatorLogBo;
import com.xmtlxx.oms.domain.bo.PropertyBo;
import com.xmtlxx.oms.domain.bo.TaskDtlBo;
import com.xmtlxx.oms.domain.vo.PhotoVo;
import com.xmtlxx.oms.domain.vo.PropertyVo;
import com.xmtlxx.oms.domain.vo.TaskDtlVo;
import com.xmtlxx.oms.domain.vo.TaskVo;
import com.xmtlxx.oms.service.IOperatorLogService;
import com.xmtlxx.oms.service.ITaskDtlService;
import com.xmtlxx.system.domain.SysOss;
import com.xmtlxx.system.service.ISysDeptService;
import com.xmtlxx.system.service.ISysNoticeService;
import com.xmtlxx.system.service.ISysOssService;
import com.xmtlxx.system.service.ISysUserService;
import com.xmtlxx.wms.domain.Deal;
import com.xmtlxx.wms.domain.ExWarehouse;
import com.xmtlxx.wms.domain.Warehouse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotEmpty;
import java.util.*;

/**
 * @author RonyChan
 * @since 2022/9/02 10:01
 */
@Validated
@Api(value = "控制中心", tags = {"业务调度控制中心"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/center")
public class CenterController extends BaseController {

    @Autowired
    private ITaskService iTaskService;

    @Autowired
    private ITaskDtlService iTaskDtlService;

    @Autowired
    private IWarehouseService iWarehouseService;

    @Autowired
    private IExWarehouseService iExWarehouseService;

    @Autowired
    private IInventoryService iInventoryService;

    @Autowired
    private IOrderService iOrderService;

    @Autowired
    private IStoreLogService iStoreLogService;

    @Autowired
    private IClientService iClientService;

    @Autowired
    private IDealService iDealService;

    @Autowired
    private IStoreService iStoreService;

    @Autowired
    private IOrderLogService iOrderLogService;

    @Autowired
    private IOperatorLogService iOperatorLogService;

    @Autowired
    private IPropertyService iPropertyService;

    @Autowired
    private ISysOssService iSysOssService;

    @Autowired
    private ISysDeptService iSysDeptService;
    @Autowired
    private final ISysUserService iSysUserService;

    @Autowired
    private final ICarService iCarService;

    @Autowired
    private final IWaybillService iWaybillService;

    @Autowired
    private final ICarrierService iCarrierService;

    @Autowired
    private final ISysNoticeService sysNoticeService;

    @Autowired
    private final OrderUtils orderUtils;

    @Autowired
    private final ICenterService centerService;

    /**
     * 下发任务订单
     */
    @ApiOperation("下发任务订单")
//    @SaCheckPermission("oms:task:add")
    @Log(title = "下发任务订单", businessType = BusinessType.INSERT)
    @GetMapping("/sendsTask/{ids}")
    public R<Void> sendsTask(@ApiParam("主键串")
                          @NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        for(String id : ids){
            TaskVo taskVo = iTaskService.queryById(id);
            TaskDtlBo dtlBo = new TaskDtlBo();
            dtlBo.setTaskId(id);
            List<TaskDtlVo> dtls = iTaskDtlService.queryList(dtlBo);
            String objId = null;
            //下发日志新增
            addOperatorLog(taskVo.getId(),"oms","下发");
            switch (taskVo.getType()){
                case "0"://入库单
                    WarehouseBo warehouseBo = new WarehouseBo();
                    warehouseBo.setTaskId(id);
                    List<WarehouseVo> warehouseVos = iWarehouseService.queryList(warehouseBo);
                    if(warehouseVos == null || warehouseVos.size() == 0){
                        warehouseBo.setType("0");
                        warehouseBo.setStoreId(taskVo.getStoreId());
                        warehouseBo.setDeptId(taskVo.getDeptId());
                        warehouseBo.setName(taskVo.getName());
                        warehouseBo.setTel(taskVo.getTel());
                        warehouseBo.setAddress(taskVo.getAddress());
                        warehouseBo.setFlag(taskVo.getDelivery());
                        warehouseBo.setLat(taskVo.getLat());
                        warehouseBo.setLng(taskVo.getLng());
                        warehouseBo.setNums(taskVo.getNums());

                        List<WarehouseDtlVo> wdtls = new ArrayList<>();
                        if(dtls != null && dtls.size() > 0){
                            for(TaskDtlVo dtl : dtls){
                                WarehouseDtlVo wdtl = new WarehouseDtlVo();
                                wdtl.setPno(dtl.getPno());
                                wdtl.setName(dtl.getName());
                                wdtl.setDeptId(dtl.getDeptId());
                                wdtl.setOrgId(dtl.getLocalId());
                                wdtl.setNums(dtl.getNums());
                                wdtl.setDelFlag("0");
                                wdtl.setStatus("0");
                                wdtls.add(wdtl);
                            }
                        }
                        warehouseBo.setItems(wdtls);
                        Warehouse warehouse =  iWarehouseService.insertByBo(warehouseBo);
                        if(warehouse != null){
                            objId = warehouse.getId();
                        }
                    }
                    else {
                        for (WarehouseVo vo:warehouseVos){
                            List<WarehouseDtlVo> wdtls = new ArrayList<>();
                            if(dtls != null && dtls.size() > 0){
                                for(TaskDtlVo dtl : dtls){
                                    WarehouseDtlVo wdtl = new WarehouseDtlVo();
                                    wdtl.setPno(dtl.getPno());
                                    wdtl.setName(dtl.getName());
                                    wdtl.setDeptId(dtl.getDeptId());
                                    wdtl.setOrgId(dtl.getLocalId());
                                    wdtl.setNums(dtl.getNums());
                                    wdtl.setDelFlag("0");
                                    wdtl.setStatus("0");
                                    wdtls.add(wdtl);
                                }
                            }
                            vo.setItems(wdtls);
                            WarehouseBo bo = new WarehouseBo();
                            BeanUtil.copyProperties(vo,bo);
                            Warehouse warehouse =  iWarehouseService.updateByBo(bo);
                        }
                        objId = warehouseVos.get(0).getId();
                    }
                    break;
                case "1"://出库单
                    ExWarehouseBo exWarehouseBo = new ExWarehouseBo();
                    exWarehouseBo.setTaskId(id);
                    List<ExWarehouseVo> exWarehouseVos = iExWarehouseService.queryList(exWarehouseBo);
                    if(exWarehouseVos == null || exWarehouseVos.size() == 0){
                        exWarehouseBo.setDeptId(taskVo.getDeptId());
                        exWarehouseBo.setStoreId(taskVo.getStoreId());
                        exWarehouseBo.setType(taskVo.getPropertyType());
                        exWarehouseBo.setReason(taskVo.getRemark());
                        exWarehouseBo.setTargetId(taskVo.getDeptId());
                        exWarehouseBo.setContacts(taskVo.getName());
                        exWarehouseBo.setTel(taskVo.getTel());
                        exWarehouseBo.setAddress(taskVo.getAddress());
                        exWarehouseBo.setLng(taskVo.getLng());
                        exWarehouseBo.setLat(taskVo.getLat());
                        exWarehouseBo.setFlag(taskVo.getDelivery());
                        exWarehouseBo.setNums(taskVo.getNums());

                        List<ExWarehouseDtlVo> exDtls = new ArrayList<>();
                        if(dtls != null && dtls.size() > 0){
                            for(TaskDtlVo dtl : dtls){
                                ExWarehouseDtlVo exwdtl = new ExWarehouseDtlVo();
                                exwdtl.setPno(dtl.getPno());
                                exwdtl.setName(dtl.getName());
                                exwdtl.setDeptId(dtl.getDeptId());
                                exwdtl.setOrgId(dtl.getLocalId());
                                exwdtl.setNums(dtl.getNums());
                                exwdtl.setDelFlag("0");
                                exwdtl.setStatus("0");
                                exDtls.add(exwdtl);
                            }
                        }
                        exWarehouseBo.setItems(exDtls);
                        ExWarehouse exWarehouse = iExWarehouseService.insertByBo(exWarehouseBo);
                        if(exWarehouse != null){
                            objId = exWarehouse.getId();
                        }
                    }
                    else {
                        for (ExWarehouseVo vo :exWarehouseVos){
                            List<ExWarehouseDtlVo> exDtls = new ArrayList<>();
                            if(dtls != null && dtls.size() > 0){
                                for(TaskDtlVo dtl : dtls){
                                    ExWarehouseDtlVo exwdtl = new ExWarehouseDtlVo();
                                    exwdtl.setPno(dtl.getPno());
                                    exwdtl.setName(dtl.getName());
                                    exwdtl.setDeptId(dtl.getDeptId());
                                    exwdtl.setOrgId(dtl.getLocalId());
                                    exwdtl.setNums(dtl.getNums());
                                    exwdtl.setDelFlag("0");
                                    exwdtl.setStatus("0");
                                    exDtls.add(exwdtl);
                                }
                            }
                            vo.setItems(exDtls);
                            ExWarehouseBo bo = new ExWarehouseBo();
                            BeanUtil.copyProperties(vo,bo);
                            ExWarehouse exWarehouse = iExWarehouseService.updateByBo(bo);
                        }


                        objId = exWarehouseVos.get(0).getId();
                    }

                    break;
                case "2"://处置单
                    DealBo dealBo = new DealBo();
                    dealBo.setTaskId(id);
                    List<DealVo> dealVos = iDealService.queryList(dealBo);
                    if(dealVos == null || dealVos.size() == 0){
                        dealBo.setDeptId(taskVo.getDeptId());
                        dealBo.setStoreId(taskVo.getStoreId());
                        dealBo.setStatus("0");
                        dealBo.setDelFlag("0");
                        dealBo.setDealType(taskVo.getDealType());

                        List<DealDtlVo> dealDtls = new ArrayList<>();
                        if(dtls != null && dtls.size() > 0){
                            for(TaskDtlVo dtl : dtls){
                                DealDtlVo dealDtl = new DealDtlVo();
                                dealDtl.setPno(dtl.getPno());
                                dealDtl.setName(dtl.getName());
                                dealDtl.setNums(dtl.getNums());
                                dealDtl.setDelFlag("0");
                                dealDtl.setStatus("0");
                                dealDtl.setDealType(taskVo.getDealType());
                                dealDtls.add(dealDtl);
                            }
                        }
                        dealBo.setItems(dealDtls);

                        Deal deal = iDealService.insertByBo(dealBo);
                        if(deal != null){
                            objId = deal.getId();
                        }
                    }
                    else {
                        for (DealVo vo : dealVos){
                            List<DealDtlVo> dealDtls = new ArrayList<>();
                            if(dtls != null && dtls.size() > 0){
                                for(TaskDtlVo dtl : dtls){
                                    DealDtlVo dealDtl = new DealDtlVo();
                                    dealDtl.setPno(dtl.getPno());
                                    dealDtl.setName(dtl.getName());
                                    dealDtl.setNums(dtl.getNums());
                                    dealDtl.setDelFlag("0");
                                    dealDtl.setStatus("0");
                                    dealDtl.setDealType(taskVo.getDealType());
                                    dealDtls.add(dealDtl);
                                }
                            }
                            vo.setItems(dealDtls);
                            DealBo bo = new DealBo();
                            BeanUtil.copyProperties(vo,bo);
                            Deal deal = iDealService.updateByBo(bo);
                        }
                        objId = dealVos.get(0).getId();
                    }

                    break;
                case "3"://调用单
                    ExWarehouseBo transferBo = new ExWarehouseBo();
                    transferBo.setTaskId(id);
                    List<ExWarehouseVo> transferVos = iExWarehouseService.queryList(transferBo);
                    if(transferVos == null || transferVos.size() == 0){
                        transferBo.setDeptId(taskVo.getDeptId());
                        transferBo.setStoreId(taskVo.getStoreId());
                        transferBo.setType(taskVo.getPropertyType());
                        transferBo.setReason(taskVo.getRemark());
                        transferBo.setTargetId(taskVo.getDeptId());
                        transferBo.setContacts(taskVo.getName());
                        transferBo.setTel(taskVo.getTel());
                        transferBo.setAddress(taskVo.getAddress());
                        transferBo.setLng(taskVo.getLng());
                        transferBo.setLat(taskVo.getLat());
                        transferBo.setFlag(taskVo.getDelivery());
                        transferBo.setReturnStatus("0");
                        transferBo.setNums(taskVo.getNums());

                        List<ExWarehouseDtlVo> exDtls = new ArrayList<>();
                        if(dtls != null && dtls.size() > 0){
                            for(TaskDtlVo dtl : dtls){
                                ExWarehouseDtlVo exwdtl = new ExWarehouseDtlVo();
                                exwdtl.setPno(dtl.getPno());
                                exwdtl.setName(dtl.getName());
                                exwdtl.setDeptId(dtl.getDeptId());
                                exwdtl.setOrgId(dtl.getLocalId());
                                exwdtl.setNums(dtl.getNums());
                                exwdtl.setDelFlag("0");
                                exwdtl.setStatus("0");
                                exDtls.add(exwdtl);
                            }
                        }
                        transferBo.setItems(exDtls);
                        ExWarehouse exWarehouse = iExWarehouseService.insertByBo(transferBo);
                        if(exWarehouse != null){
                            objId = exWarehouse.getId();
                        }
                    }
                    else {
                        for (ExWarehouseVo vo :transferVos){
                            List<ExWarehouseDtlVo> exDtls = new ArrayList<>();
                            if(dtls != null && dtls.size() > 0){
                                for(TaskDtlVo dtl : dtls){
                                    ExWarehouseDtlVo exwdtl = new ExWarehouseDtlVo();
                                    exwdtl.setPno(dtl.getPno());
                                    exwdtl.setName(dtl.getName());
                                    exwdtl.setDeptId(dtl.getDeptId());
                                    exwdtl.setOrgId(dtl.getLocalId());
                                    exwdtl.setNums(dtl.getNums());
                                    exwdtl.setDelFlag("0");
                                    exwdtl.setStatus("0");
                                    exDtls.add(exwdtl);
                                }
                            }
                            vo.setItems(exDtls);
                            ExWarehouseBo bo = new ExWarehouseBo();
                            BeanUtil.copyProperties(vo,bo);
                            ExWarehouse exWarehouse = iExWarehouseService.updateByBo(bo);
                        }

                        objId = transferVos.get(0).getId();
                    }

                    break;
                default:

                    break;
            }
            if(taskVo.getDelivery() != null && taskVo.getDelivery().equals("0")){
                OrderBo orderBo = new OrderBo();
                orderBo.setTaskId(taskVo.getId());
                orderBo.setObjId(objId);
                List<OrderVo> orderVos = iOrderService.queryList(orderBo);
                if(orderVos == null || orderVos.size() == 0){
                    orderBo.setDeptId(taskVo.getDeptId());
                    orderBo.setStatus("0");
                    orderBo.setType("0");
                    //根据部门 从承运商客户表获取 承运商信息 无承运商 不下发配送；
                    //有承运商关系：
                    // 入库订单，取客户表信息为收件信息，任务单联系人为寄件人信息；
                    // 出库订单，取客户表信息为寄件人信息，任务单联系人为收件人信息；

                    //客户信息
                    ClientBo clientBo = new ClientBo();
                    clientBo.setDeptId(taskVo.getDeptId());
                    List<ClientVo> clientVos = iClientService.queryList(clientBo);
                    ClientVo clientVo = null;
                    if(clientVos != null && clientVos.size() > 0){
                        clientVo = clientVos.get(0);
                    }
                    if(ObjectUtil.isNotNull(clientVo)){
                        orderBo.setClientId(clientVo.getId());
                        orderBo.setClientContacts(clientVo.getContacts());
                        orderBo.setClientTel(clientVo.getTel());
                        orderBo.setClientName(clientVo.getName());
                    }
                    StoreVo store = iStoreService.queryById(taskVo.getStoreId());
                    //归属申请单：0.入库，1.出库(移送),2.处置,3.调用
                    switch (taskVo.getType()){
                        case "0":
                            //设置寄件人
                            orderBo.setSendAddr(store.getName());
                            orderBo.setSendAddress(store.getAddress());
                            orderBo.setSendLng(store.getLng());
                            orderBo.setSendLat(store.getLat());
                            orderBo.setSendContacts(store.getNickName());
                            orderBo.setSendTel(store.getPhonenumber());

                            //设置收件人
                            if(ObjectUtil.isNotNull(clientVo)){
                                orderBo.setTakeAddr(clientVo.getDeptName());
                                orderBo.setTakeAddress(clientVo.getAddress());
                                orderBo.setTakeTel(clientVo.getTel());
                                orderBo.setTakeContacts(clientVo.getContacts());
                                orderBo.setTakeLat(clientVo.getLat());
                                orderBo.setTakeLng(clientVo.getLng());

                            }
                            break;
                        case "1":
                            //设置收件人
                            orderBo.setTakeAddr(taskVo.getTakeDeptName());
                            orderBo.setTakeAddress(taskVo.getTakeAddress());
                            orderBo.setTakeLng(taskVo.getTakeLng());
                            orderBo.setTakeLat(taskVo.getTakeLat());
                            orderBo.setTakeContacts(taskVo.getTakeContacts());
                            orderBo.setTakeTel(taskVo.getTakeTel());
                            //设置寄件人
                            if(ObjectUtil.isNotNull(clientVo)){
                                orderBo.setSendAddr(clientVo.getDeptName());
                                orderBo.setSendAddress(clientVo.getAddress());
                                orderBo.setSendContacts(clientVo.getContacts());
                                orderBo.setSendLat(clientVo.getLat());
                                orderBo.setSendLng(clientVo.getLng());
                                orderBo.setSendAddress(clientVo.getAddress());
                                orderBo.setSendTel(clientVo.getTel());
                            }
                            break;
                        case "3":
                            //设置收件人
                            orderBo.setTakeAddr(store.getName());
                            orderBo.setTakeAddress(store.getAddress());
                            orderBo.setTakeLng(store.getLng());
                            orderBo.setTakeLat(store.getLat());
                            orderBo.setTakeContacts(store.getNickName());
                            orderBo.setTakeTel(store.getPhonenumber());

                            //设置寄件人
                            if(ObjectUtil.isNotNull(clientVo)){
                                orderBo.setSendAddr(clientVo.getDeptName());
                                orderBo.setSendAddress(clientVo.getAddress());
                                orderBo.setSendContacts(clientVo.getContacts());
                                orderBo.setSendLat(clientVo.getLat());
                                orderBo.setSendLng(clientVo.getLng());
                                orderBo.setSendAddress(clientVo.getAddress());
                                orderBo.setSendTel(clientVo.getTel());
                            }
                            break;
                        default:
                            break;
                    }

                    //设置货物信息
                    List<OrderDtlVo> orderDtls = new ArrayList<>();
                    if(dtls != null && dtls.size() > 0){
                        for(TaskDtlVo dtl : dtls){
                            OrderDtlVo orderDtl = new OrderDtlVo();
                            orderDtl.setPno(dtl.getPno());
                            orderDtl.setName(dtl.getName());
                            orderDtl.setNums(dtl.getNums());
                            orderDtl.setDelFlag("0");
                            orderDtl.setStatus("0");
                            orderDtls.add(orderDtl);
                        }
                    }
                    orderBo.setItems(orderDtls);
                    iOrderService.insertByBo(orderBo);
                }else {
                    for (OrderVo vo :orderVos){
                        //设置货物信息
                        List<OrderDtlVo> orderDtls = new ArrayList<>();
                        if(dtls != null && dtls.size() > 0){
                            for(TaskDtlVo dtl : dtls){
                                OrderDtlVo orderDtl = new OrderDtlVo();
                                orderDtl.setPno(dtl.getPno());
                                orderDtl.setName(dtl.getName());
                                orderDtl.setNums(dtl.getNums());
                                orderDtl.setDelFlag("0");
                                orderDtl.setStatus("0");
                                orderDtls.add(orderDtl);
                            }
                        }
                        vo.setItems(orderDtls);
                        OrderBo bo = new OrderBo();
                        BeanUtil.copyProperties(vo,bo);
                        iOrderService.updateByBo(bo);
                    }
                }

                //订单日志 0 创建订单/待取件; 1.待派车;2.运输中;3.已完成;-1.作废
                OrderLogBo logBo = new OrderLogBo();
                logBo.setId(IdUtil.simpleUUID());
                logBo.setOrderId(orderBo.getId());
                logBo.setLogTime(new Date());
                logBo.setUserId(LoginHelper.getUserId());
                logBo.setOperator(LoginHelper.getUsername());
                logBo.setLogType("0");
                logBo.setDelFlag("0");
                logBo.setContent(JsonUtils.toJsonString(orderBo));
                iOrderLogService.insertByBo(logBo);

            }

            //下发后 记录仓库日志 0-入库；1-出库 2-处置 3-上架 4-挑拣 5-看样
            StoreLogBo logBo = new StoreLogBo();
            logBo.setDeptId(taskVo.getDeptId());
            logBo.setStoreId(taskVo.getStoreId());
            logBo.setLogTime(new Date());
            logBo.setUserId(LoginHelper.getUserId());
            logBo.setOperator(LoginHelper.getUsername());
            logBo.setLogType(taskVo.getType());
            logBo.setDelFlag("0");
            logBo.setContent(JsonUtils.toJsonString(taskVo));
            iStoreLogService.insertByBo(logBo);

        }
        return toAjax(1 );
    }

    /**
     * 下发任务订单
     */
    @ApiOperation("下发任务订单")
    @Transactional(rollbackFor = Exception.class)
    @Log(title = "下发任务订单", businessType = BusinessType.INSERT)
    @PostMapping("/sendsTaskV2")
    public R<Void> sendsTaskV2(@RequestBody SendTaskVo vo){
        centerService.sendsTask(vo);
        return null;
    }

    /**
     * 查询库存列表
     */
    @ApiOperation("查询库存列表")
    @SaCheckPermission("datas:query:inventory")
    @GetMapping("/inventory/list")
    public TableDataInfo<InventoryVo> list(@Validated(QueryGroup.class) InventoryBo bo, PageQuery pageQuery) {
        return iInventoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询财物列表
     */
    @ApiOperation("查询财物列表")
    @SaCheckPermission("datas:query:property")
    @GetMapping("/property/list")
    public TableDataInfo<PropertyVo> list(@Validated(QueryGroup.class) PropertyBo bo, PageQuery pageQuery) {
        return iPropertyService.queryPageList(bo, pageQuery);
    }

    @ApiOperation("判断物品是否车辆")
    @GetMapping("/queryPno/{pno}")
    public R<Boolean> queryPno(@ApiParam("主键串")
                                @NotEmpty(message = "主键不能为空")
                                @PathVariable String pno){

        return R.ok(iPropertyService.queryByPno(pno));
    }

    @ApiOperation("获取地域信息")
    @GetMapping("/queryPnoByRegion/{pno}")
    public R<String> queryPnoByRegion(@ApiParam("主键串")
                               @NotEmpty(message = "主键不能为空")
                               @PathVariable String pno){

        return R.ok(iPropertyService.queryPnoByRegion(pno));
    }

    @ApiOperation("高拍仪拍照")
    @PostMapping("/uploadPhotoBase64")
    @Transactional(rollbackFor = Exception.class)
    public R<Map<String,String>> uploadPhotoBase64(@Validated(AddGroup.class) @RequestBody PhotoVo vo){
       MultipartFile file =  BASE64DecodedMultipartFile.base64ToMultipart(vo.getBase64Url());
        Map<String,Object> params = new HashMap<>();
        String text = LoginHelper.getNickname()+"_"
            + DateUtils.date2String(new Date(),"HH:mm:ss.SSS")+"_"
            +DateUtils.date2String(new Date(),"yyyy-MM-dd");
        params.put("mark",1);
        params.put("text",text);
       SysOss oss = iSysOssService.upload(file,params,vo.getBuss(),vo.getObjid());

        Map<String, String> map = new HashMap<>(2);
        map.put("url", oss.getUrl());
        map.put("fileName", oss.getFileName());
        map.put("ossId", oss.getOssId().toString());
        return R.ok(map);
    }

    /**
     * 获取承运商
     */
    @ApiOperation("获取承运商")
    @GetMapping("/getCarrierUser")
    public R<List<SysUser>> getCarrierUser(){
        return R.ok(iSysUserService.selectUserAll("centercangguang",null));
    }


    @ApiOperation("待办事项")
    @GetMapping("/indexSchedule")
    public R<Map<String,Object>> indexSchedule(){
        return R.ok(centerService.indexScheduleV2());
    }

    //日志添加
    public void  addOperatorLog(String objid,String type,String content){
        OperatorLogBo log = new OperatorLogBo();
        log.setObjid(objid);
        log.setLogTime(new Date());
        log.setUserId(LoginHelper.getUserId());
        log.setOperator(LoginHelper.getNickname());
        log.setLogType(type);
        log.setContent(content);
        iOperatorLogService.insertByBo(log);
    }

}
